package com.wutuo.roster.provider.service;

import cn.apestar.chat.enums.AuditStateEnum;
import cn.apestar.core.base.BaseService;
import cn.apestar.core.base.GenericMapper;
import com.wutuo.roster.api.ChildApplyAPIService;
import com.wutuo.roster.api.request.ChildApplyRequest;
import com.wutuo.roster.api.request.ListChildApplyRequest;
import com.wutuo.roster.api.response.ChildApplyResponse;
import com.wutuo.roster.provider.dao.ChildApplyMapper;
import com.wutuo.roster.provider.domain.ChildApply;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 孩子申请 <br>
 *
 * @author lvh
 * @version 1.0
 */
@Service public class ChildApplyService extends BaseService<ChildApply, Long>
    implements ChildApplyAPIService {

    private Logger logger = LoggerFactory.getLogger(ChildApplyService.class);

    @Autowired private ChildApplyMapper childApplyMapper;

    @Override protected GenericMapper<ChildApply, Long> getMapper() {

        // TODO Auto-generated method stub
        return childApplyMapper;
    }

    public void addorUpdate(ChildApplyRequest record) {

        if (record.getId() == null) {
            record.setState(AuditStateEnum.TG_DD.getValue());
            super.add(record);
        } else
            super.update(record);
    }

    public void del(Long id) {

        ChildApplyRequest model = new ChildApplyRequest();
        model.setId(id);
        super.delete(model);
    }

    public List<ChildApplyResponse> lisForPage(ListChildApplyRequest request) {

        List<ChildApplyResponse> list = childApplyMapper.lisForPage(request);
        return list;
    }

    public List<ChildApplyResponse> list(ChildApplyRequest request) {

        request.setDelFlag(true);
        return childApplyMapper.list(request);
    }

    /**
     * 更新审核状态 - 审核通过
     *
     * @return void
     * @author lvh 2016年3月30日 上午9:10:59</br>
     */
    public void updateStateSuccess(Long id) {

        ChildApplyRequest request = new ChildApplyRequest();
        request.setId(id);
        request.setState(AuditStateEnum.TG_TG.getValue());
        childApplyMapper.updateByPrimaryKeySelective(request);

    }

    public ChildApply find(Long id) {
        return super.find(id);
    }
}